package com.dongnao.canvas.lsn_5_canvas;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.PorterDuff;
import android.graphics.PorterDuffXfermode;
import android.graphics.RectF;
import android.util.Log;
import android.view.View;

/**
 * <h3>Description</h3>
 * TODO
 * <h3>Author</h3> luzhenbang
 * <h3>Date</h3> 2018/6/25 14:46
 * <h3>Copyright</h3> Copyright (c) 2018 Shenzhen ChinaSoft International Co., Ltd. Inc. All rights reserved.
 */
class MyFlayerView extends View {

    private Paint mPaint;
    int mCircleColor = 0xffffcc44;//黄色
    int mRectColor = 0xff66aaff;//蓝色
    private String TAG = "data" ;

    public MyFlayerView(Context context) {
        super(context);
        mPaint = new Paint();
        mPaint.setColor(mCircleColor);
        mPaint.setStyle(Paint.Style.FILL);
    }

    @Override
    protected void onDraw(Canvas canvas) {
        super.onDraw(canvas);

        //dst图形
        canvas.drawColor(Color.GREEN);

        Log.e(TAG,canvas.getSaveCount() + "");
        int layer = canvas.saveLayer(new RectF(0, 0, canvas.getWidth(), canvas.getHeight()), mPaint);
        Log.e(TAG,canvas.getSaveCount() + "");

        canvas.drawCircle(200,200,200,mPaint);

        //sr图形
        mPaint.setColor(mRectColor);
        mPaint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_OUT));
        Log.e(TAG,canvas.getSaveCount() + "");
        canvas.drawRect(new RectF(200,200,600,600),mPaint);
        mPaint.setXfermode(null);
        canvas.restoreToCount(layer);

    }



}
